package top.zhangjianyong.tools.factory;

import top.zhangjianyong.tools.entity.AliBill;
import top.zhangjianyong.tools.utils.DateTimeUtil;
import top.zhangjianyong.tools.utils.StringUtil;

import java.math.BigDecimal;
import java.util.List;

public class AliBillFactory {
    public static AliBill create() {
        return new AliBill();
    }

    public static AliBill create(String line, Long fileId) {
        AliBill aliBill = create();
        List<String> split = StringUtil.regexSplit(line, ",");
        /*交易时间,交易分类,交易对方,对方账号,商品说明,收/支 ,金额  ,收/付款方式,交易状态,交易订单号,商家订单号 ,备注  ,*/
        if (split.size() < 11) throw new RuntimeException("分割对账数据异常");

        aliBill.setTradeTime(DateTimeUtil.localDateTime(split.get(0), "yyyy-MM-dd HH:mm:ss"));//交易时间
        aliBill.setType(split.get(1));//交易分类
        aliBill.setCounterparty(split.get(2));//交易对方
        aliBill.setCounterpartyAccount(split.get(3));//对方账号
        aliBill.setCommodity(split.get(4));//商品说明
        aliBill.setInOrOut(split.get(5));//收/支
        aliBill.setAmt(new BigDecimal(split.get(6)));//金额
        aliBill.setPayWay(split.get(7));//收/付款方式
        aliBill.setState(split.get(8));//交易状态
        aliBill.setOrderNo(split.get(9));//交易订单号
        aliBill.setMerchantOrderNo(split.get(10));//商家订单号
        aliBill.setRemark(split.get(11));

        aliBill.setConvertState("初始");
        aliBill.setFileId(fileId);
        return aliBill;
    }
}
